package com.ruoyi.common.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SmsUtils {

    static Logger log = LoggerFactory.getLogger(SmsUtils.class);

    private static final String regionId = "cn-hangzhou";
    private static final String accessKeyId = "LTAI5tB8wZxoc5Z8o8DtWmaV";
    private static final String accessSecret = "1OL2KPSaNQrAxW4BYKaLeQ4sGJCiI7";
    private static final String domain = "dysmsapi.aliyuncs.com";
    private static final String version = "2017-05-25";
    private static final String action = "SendSms";

    private static final String SIGNNAME="沁丝堂";
    private static final String TEMPLATECODE = "SMS_220625283";

    public static boolean sendSms(String phoneNumbers,String TemplateParam){
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain(domain);
        request.setSysVersion(version);
        request.setSysAction(action);
        request.putQueryParameter("RegionId", regionId);
        request.putQueryParameter("PhoneNumbers", phoneNumbers);
        request.putQueryParameter("SignName", SIGNNAME);
        request.putQueryParameter("TemplateCode", TEMPLATECODE);
        request.putQueryParameter("TemplateParam", TemplateParam);
        try {
            CommonResponse response = client.getCommonResponse(request);
            log.info(response.getData());
            return true;
        } catch (Exception e) {
            log.error("=====================>发送验证码失败{}" + e.getMessage(), e);
        }
        return false;
    }

    public static void main(String[] args) {
        sendSms("13735514558","{\"name\":\"刘攀\",\"store\":\"海曙门店生发堂\"}");
    }
}
